/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MainUtama;

import Database.CheckConnection;
import FrameAdmin.*;
import Model.UserSekre;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

/**
 *
 * @author WIN7
 */
public class AdminFrameUtama extends JFrame {

    private JMenuBar menuBar;
    private JMenu tabel, info, admin;
    private JMenuItem hapustabel, buattabel, lihatUser, tentang, tambahUser, close;
    private ArrayList<UserSekre> dataSekre;

    public AdminFrameUtama() throws HeadlessException {
        this.setTitle("Administrator Sekretariat USD");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setBounds(350, 200, 500, 400);
        this.setLayout(null);

        menuBar = new JMenuBar();
        menuBar.setSize(500, 30);
        this.add(menuBar);

        admin = new JMenu("Menu");
        admin.setSize(70, 30);
        menuBar.add(admin);

        tambahUser = new JMenuItem("Tambah User Sekretariat");
        tambahUser.setSize(70, 30);
        admin.add(tambahUser);
        tambahUser.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                Admintambahuser tmbhuser = new Admintambahuser();
                tmbhuser.setVisible(true);
            }
        });

        lihatUser = new JMenuItem("Daftar User Sekretariat");
        lihatUser.setSize(70, 30);
        admin.add(lihatUser);
        lihatUser.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                dataSekre = new ArrayList<UserSekre>();
                Connection con = CheckConnection.open("jdbc:oracle:thin:@localhost:1521:XE", "hr", "12345");
                Statement stat = null;
                try {
                    stat = con.createStatement();
                } catch (SQLException ex) {
                    Logger.getLogger(AdminFrameUtama.class.getName()).log(Level.SEVERE, null, ex);
                }
                String sql = "select * from USER_SEKRETARIAT";
                ResultSet hasil = null;
                try {
                    hasil = stat.executeQuery(sql);
                } catch (SQLException ex) {
                    Logger.getLogger(AdminFrameUtama.class.getName()).log(Level.SEVERE, null, ex);
                }
                try {
                    while (hasil.next()) {
                        UserSekre sekre = new UserSekre();
                        try {
                            sekre.setIdUserSekre(hasil.getString("ID_SEKRETARIAT"));
                            sekre.setNamaUserSekre(hasil.getString("NAMA_SEKRETARIAT"));
                            dataSekre.add(sekre);
                        } catch (Exception ex) {
                            Logger.getLogger(AdminFrameUtama.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                } catch (SQLException ex) {
                    Logger.getLogger(AdminFrameUtama.class.getName()).log(Level.SEVERE, null, ex);
                }
                DaftarUser daftar = new DaftarUser(dataSekre);
                daftar.setVisible(true);
            }
        });

        close = new JMenuItem("Exit");
        close.setSize(70, 30);
        admin.add(close);
        close.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });

        tabel = new JMenu("Tabel");
        tabel.setSize(70, 30);
        menuBar.add(tabel);

        buattabel = new JMenuItem("Buat Tabel");
        buattabel.setSize(70, 30);
        tabel.add(buattabel);
        buattabel.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                FrameBuatTabel buat = new FrameBuatTabel();
                buat.setVisible(true);
            }
        });

        hapustabel = new JMenuItem("Hapus Tabel");
        hapustabel.setSize(70, 30);
        tabel.add(hapustabel);
        hapustabel.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                HapusTabel hapus = new HapusTabel();
                hapus.setVisible(true);
            }
        });

        info = new JMenu("Info");
        info.setSize(70, 30);
        menuBar.add(info);

        tentang = new JMenuItem("Tentang");
        tentang.setSize(70, 30);
        info.add(tentang);
        tentang.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                Frametentang ft = new Frametentang();
                ft.setVisible(true);
            }
        });
    }

    public static void main(String[] args) {
        AdminFrameUtama admin = new AdminFrameUtama();
        admin.setVisible(true);
    }
}
